﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using DotConferenceSql;
using NUnit.Framework.SyntaxHelpers;

namespace TestDotConferenceSql
{
    [TestFixture]
    public class TestInnerJoinQueryElement
    {
        SqlQuery query;
        InnerJoinQueryElement joinElement;

        [SetUp]
        public void Init()
        {
            query = new SqlQuery();
            joinElement = new InnerJoinQueryElement();
        }

        [Test]
        public void InnerJoinElementWithoutSqlQuery()
        {
            joinElement.ForeignTable = "Foreign";
            joinElement.Condition = "Test.id = Foreign.id";

            Assert.That(joinElement.BuildTextQuery(), Text.Contains("INNER JOIN Foreign ON Test.id = Foreign.id"));
        }

        [Test]
        public void InnerJoinElementWithSqlQuery()
        {
            query.Elements.Add(new InnerJoinQueryElement("Foreign", "Test.id = Foreign.id"));

            Assert.That(query.BuildTextQuery(), Text.Contains("INNER JOIN Foreign ON Test.id = Foreign.id"));
        }

        [Test]
        public void MultipleInnerJoinElementWithSqlQuery()
        {
            joinElement.ForeignTable = "Foreign1";
            joinElement.Condition = "Test.id = Foreign1.id";

            query.Elements.Add(new InnerJoinQueryElement("Foreign2", "Test.name = Foreign2.name"));
            query.Elements.Add(joinElement);

            Assert.That(query.BuildTextQuery(), Text.Contains("INNER JOIN Foreign1 ON Test.id = Foreign1.id INNER JOIN Foreign2 ON Test.name = Foreign2.name"));
        }
    }
}
